// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int isInRange(const char *range, const char *dbsuffix)
{
	const char *pre, *q, *last; 
	char buf[10];
	int suffix, low, high, value;
	int flag=0;
	suffix=atoi(dbsuffix);

	pre=range;
	last=range;
	while (last != '\0') {
		while(*last != ',' && *last != '\0') {
			last++;
			if (*last == '-') flag = 1;
		}
		if (flag == 0)
		{
			strncpy(buf, pre, last-pre);
			buf[last-pre] = '\0';
			value = atoi(buf);
			if (value == suffix) return 1;
			if (*last == '\0') return 0;
			last++;
			pre = last;
		} 
		else
		{
			q = pre;
			while (*q != '-')
				q++;
			strncpy(buf, pre, q-pre);
			buf[q-pre] = '\0';
			low = atoi(buf);
			q++;
			strncpy(buf, q, last-q);
			buf[last-q] = '\0';
			high = atoi(buf);
			if (suffix >= low && suffix <= high) return 1;
			if (*last == '\0') return 0;
			last++;
			pre = last;
		}
		flag = 0;
	} 

	return 0;
}

int main(int argc, char* argv[])
{
	char *range="0-4,7,8,44,56-67";
	char *dbsuffix="68";
	printf("Hello World!\n");
	printf("%d\n",isInRange(range, dbsuffix));

	
	return 0;
}

